When rewriting data written into a nonvolatile memory such as a flash read only memory (flash ROM) in an electronic control unit, a method such as disclosed in Japanese Patent Application Laid-open Publication No. H9(1997)-128229 (Patent Document 1) has been adopted. That is, after content of a data rewrite area of the nonvolatile memory is erased in response to an instruction from a tool connected to the electronic control unit, data successively sent from the tool is rewritten into the nonvolatile memory.
However, when rewriting data only partially different from data which has been written into the nonvolatile memory, it is necessary to erase all data in the data rewrite area and then to transfer all data from the tool to the electronic control unit. Thus, combined with a slow data transfer speed, a long time is needed to rewrite data in the nonvolatile memory.
Therefore, an object of the present invention is to provide an electronic control unit and a method for rewriting data, capable of reducing the time needed to rewrite data in the nonvolatile memory such as flash ROM.
This and other objects are addressed by an electronic control unit includes: a nonvolatile memory capable of erasing data in units of erasure blocks and also writing data in units of write blocks smaller than the erasure blocks; and a processor, and the electronic control unit is mounted in an automobile. Then, in response to a data rewrite request from outside, the processor of the electronic control unit saves data written into a portion of the nonvolatile memory in a volatile memory and then erases the data, in units of erasure blocks, determines an identity of identification information of data to be written into the nonvolatile memory and identification information of the data saved in the volatile memory, in units of write blocks, and writes the data saved in the volatile memory into the nonvolatile memory when the identity is established, and writes data from outside into the nonvolatile memory when the identity is not established. Thus, the time needed to rewrite data in a non-volatile memory such as flash ROM can be reduced.